package com.wyx.action;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;


public class BaseAction {
	//解耦方式访问servlet API
	public Map<String, Object> getMapRequest(){
		return (Map<String, Object>) ActionContext.getContext().get("request");
	}
	
	public Map<String, Object> getMapSession(){
		return (Map<String, Object>) ActionContext.getContext().getSession();
	}
	
	public Map<String, Object> getMapApplication(){
		return (Map<String, Object>) ActionContext.getContext().getApplication();
	}
	
	//耦合方式访问servlet API
	public HttpServletRequest getRequest(){
		return ServletActionContext.getRequest();
	}
	
	public HttpSession getSession(){
		return ServletActionContext.getRequest().getSession();
	}
	
	//得到response对象
	public HttpServletResponse getResponse(){
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setContentType("text/html;charset=UTF-8");
		return response;
	}

}
